<template>
  <!--我的员工-->
  <div>
    <div class="search">
      <input type="text" placeholder="销售姓名/手机号搜索" v-model="content">
      <img src="../../assets/search.png" alt="" width="16" @click="goSearch()">
    </div>
    <div class="page-infinite-wrapper" ref="wrapper" :style="{ height: wrapperHeight + 'px' }">
      <wv-group
        v-infinite-scroll="getList"
        infinite-scroll-disabled="loading"
        infinite-scroll-distance="10"
      >
        <ul class="list">
          <li v-for="(item,index) in employeeList">
            <ul>
              <li>{{item.employeeName}} <span>{{item.employeePhone}}</span></li>
              <li>地区：{{item.airportName}}</li>
              <li><span>开通时间：{{item.createDate}}</span>
                <wv-button type="default" :mini="true" class="lookdetail" @click="goFrozenEmployee(item.employeeId)"
                           v-if="item.isEnable==1">冻结
                </wv-button>
                <wv-button type="default" :mini="true" class="dongjie" v-if="item.isEnable==0">已冻结</wv-button>
                <wv-button type="default" :mini="true" class="lookdetail" v-if="item.isEnable==2">已注销</wv-button>
              </li>
            </ul>
          </li>
        </ul>
      </wv-group>
    </div>
    <div class="model" v-show="isVisible">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../assets/close.png" alt="" width="15" @click="isVisible=false">
        冻结后将停止该销售的所有权限 是否确认冻结
        <p class="btn">
          <button @click="isVisible=false">确定</button>
          <button @click="isVisible=false">取消</button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getMyEmployee, employeeFrozen} from '../../../test/unit/http'
  import {Toast} from 'we-vue'

  export default {
    name: '',
    props: {},
    data() {
      return {
        isVisible: false,
        employeeList: [],
        content: '',
        wrapperHeight: 0,
        page: 1,
        rows: 10,
        loading: false,
        pages: 0,
        totalNum: 0
      };
    },
    methods: {
      getList(){
        let params={
          page:this.page,
          rows:this.rows,
          content:this.content
        };
        getMyEmployee(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            let data = res.object;
            let list = data.rows;
            let pages = data.pages;
            let page = data.page;
            this.page = page;
            this.pages = pages;
            let totalNum = data.totalNum;
            this.totalNum = totalNum;
            if (list.length > 0) {
              this.employeeList = this.employeeList.concat(list);
            }
            if (this.page < this.pages) {
              this.page++;
              this.loading = false
            } else {
              this.loading = true
            }
          } else {
            Toast.text(res.info);
          }
        })
      },
      goSearch() {
        this.page=1;
        this.employeeList=[];
        this.getList();
      },
      goFrozenEmployee(employeeId) {
        employeeFrozen({employeeId: employeeId}).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.goSearch();
          }
        })
      }
    },
    created() {
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;

    img {
      position: absolute;
      right: 10px;
      top: 10px
    }

    .btn {
      text-align: center;

      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }

      button:last-child {
        background-color: #ccc;
        border: 1px solid #ccc;
      }

      button:first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }


  }

  .search {
    position: relative;
    width: 95%;
    margin: 10px auto;

    input {
      width: 90%;
      border: 1px solid #eee;
      box-shadow: 0 3px 4px rgba(17, 17, 17, 0.05);
      border-radius: 7px;
      height: 25px;
      line-height: 25px;
      padding: 10px;
      color: #111;
    }

    img {
      position: absolute;
      right: 20px;
      top: 16px;
    }
  }

  .list {
    padding: 10px 15px;
    text-align: left;

    > li {
      border-bottom: 1px solid #ddd;
      margin-bottom: 10px;

      li:first-child {
        font-size: 16px;
        color: #111;
        font-weight: 700;
        margin-bottom: 5px;

        span {
          color: #999;
          margin-left: 10px;
        }
      }

      li:nth-child(2), li:last-child {
        font-size: 12px;
        color: #666;
      }

      li:last-child {
        display: flex;

        button {
          background-color: #fb556a;
          color: #fff;
          margin-bottom: 10px;
        }

        .dongjie {
          background-color: #f9d0d5;
          width: 90px;
        }

        span {
          flex: 0 78%;
          margin-top: 6px;
        }
      }
    }

    > li:last-child {
      border-bottom: none;
    }
  }
</style>
